//package com.example.demo.rabbitMQ.controller;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Scope;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.annotation.Transactional;
//
//import javax.annotation.PostConstruct;
//
///**
// * <p>Description: RabbitMQ消息发送类 </p>
// *
// * @author Eric Lee
// * @version v1.0.0
// * @since 2021/8/4 18:43
// **/
//@Slf4j
////@Component
//public class RabbitSender implements RabbitTemplate.ReturnCallback {
//
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//    @Transactional(rollbackFor = Exception.class, transactionManager = "rabbitTransactionManager")
//    public void sendMsgQueue(String msg) {
//        log.info("进闸消息已发送 {}", msg);
//        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
//        //设置返回回调
//        rabbitTemplate.setReturnCallback(this);
//        //设置确认回调
//        rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> {
//            if (ack) {
//                log.info("消息发送成功！");
//            } else {
//                log.info("消息发送失败，" + cause + correlationData.toString());
//            }
//        });
//        rabbitTemplate.convertAndSend("directExchange", "orange", msg);
//    }
//
//    @Override
//    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
//        log.info("消息被退回 {}", message.toString());
//    }
//}
